home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / record / recordnu.frm < prev   
Text File  |  1995-05-02  |  6KB  |  280 lines

  1. VERSION 2.00
  2. Begin Form RecordNumberfrm 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Record Numbers"
  5.    ClientHeight    =   4080
  6.    ClientLeft      =   1320
  7.    ClientTop       =   1830
  8.    ClientWidth     =   6285
  9.    Height          =   4485
  10.    Left            =   1260
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4080
  13.    ScaleWidth      =   6285
  14.    Top             =   1485
  15.    Width           =   6405
  16.    Begin CommandButton Command4 
  17.       Caption         =   "<"
  18.       Height          =   330
  19.       Left            =   1500
  20.       TabIndex        =   5
  21.       Top             =   1665
  22.       Width           =   480
  23.    End
  24.    Begin CommandButton Command3 
  25.       Caption         =   "<<"
  26.       Height          =   330
  27.       Left            =   960
  28.       TabIndex        =   4
  29.       Top             =   1665
  30.       Width           =   480
  31.    End
  32.    Begin CommandButton Command2 
  33.       Caption         =   ">>"
  34.       Height          =   330
  35.       Left            =   4590
  36.       TabIndex        =   3
  37.       Top             =   1680
  38.       Width           =   480
  39.    End
  40.    Begin Data Data1 
  41.       Connect         =   ""
  42.       DatabaseName    =   "C:\VB\BIBLIO.MDB"
  43.       Exclusive       =   0   'False
  44.       Height          =   270
  45.       Left            =   1650
  46.       Options         =   0
  47.       ReadOnly        =   0   'False
  48.       RecordSource    =   "Titles"
  49.       Top             =   2970
  50.       Width           =   2835
  51.    End
  52.    Begin TextBox Text1 
  53.       DataField       =   "Title"
  54.       DataSource      =   "Data1"
  55.       Height          =   345
  56.       Left            =   1155
  57.       TabIndex        =   1
  58.       Top             =   435
  59.       Width           =   3990
  60.    End
  61.    Begin CommandButton Command1 
  62.       Caption         =   ">"
  63.       Height          =   330
  64.       Left            =   4050
  65.       TabIndex        =   0
  66.       Top             =   1680
  67.       Width           =   480
  68.    End
  69.    Begin Shape Shape1 
  70.       Height          =   1140
  71.       Index           =   1
  72.       Left            =   510
  73.       Top             =   1185
  74.       Width           =   5505
  75.    End
  76.    Begin Shape Shape1 
  77.       Height          =   1140
  78.       Index           =   0
  79.       Left            =   510
  80.       Top             =   2490
  81.       Width           =   5505
  82.    End
  83.    Begin Label Label3 
  84.       BackStyle       =   0  'Transparent
  85.       Caption         =   "Field Name"
  86.       ForeColor       =   &H00800000&
  87.       Height          =   270
  88.       Left            =   1170
  89.       TabIndex        =   8
  90.       Top             =   165
  91.       Width           =   2520
  92.    End
  93.    Begin Label Label2 
  94.       Alignment       =   2  'Center
  95.       BackStyle       =   0  'Transparent
  96.       Caption         =   "Label with buttons"
  97.       ForeColor       =   &H00800000&
  98.       Height          =   225
  99.       Index           =   1
  100.       Left            =   1965
  101.       TabIndex        =   7
  102.       Top             =   1395
  103.       Width           =   2040
  104.    End
  105.    Begin Label Label2 
  106.       Alignment       =   2  'Center
  107.       BackStyle       =   0  'Transparent
  108.       Caption         =   "Data Control"
  109.       ForeColor       =   &H00800000&
  110.       Height          =   225
  111.       Index           =   0
  112.       Left            =   1995
  113.       TabIndex        =   6
  114.       Top             =   2715
  115.       Width           =   2040
  116.    End
  117.    Begin Label Label1 
  118.       BorderStyle     =   1  'Fixed Single
  119.       Height          =   285
  120.       Left            =   2070
  121.       TabIndex        =   2
  122.       Top             =   1695
  123.       Width           =   1875
  124.    End
  125. End
  126. Option Explicit
  127. Dim TotRec As Long
  128. Dim CurrRec As Long
  129. Dim JustUsedFind As Integer        'flag for find function
  130.  
  131. Sub Command1_Click ()
  132. On Error Resume Next
  133.    Data1.Recordset.MoveNext
  134.  
  135. If Data1.Recordset.EOF Then
  136.    Data1.Recordset.MoveLast
  137.    MsgBox "This is the end of the database"
  138.    Exit Sub
  139. End If
  140.  
  141. End Sub
  142.  
  143. Sub Command2_Click ()
  144. On Error Resume Next
  145.    Data1.Recordset.MoveLast
  146.  
  147. End Sub
  148.  
  149. Sub Command3_Click ()
  150. On Error Resume Next
  151.    Data1.Recordset.MoveFirst
  152.  
  153. End Sub
  154.  
  155. Sub Command4_Click ()
  156. On Error Resume Next
  157.    Data1.Recordset.MovePrevious
  158.  
  159. If Data1.Recordset.BOF Then
  160.    Data1.Recordset.MoveFirst
  161.    MsgBox "This is the beginning of the database"
  162.    Exit Sub
  163. End If
  164.  
  165. End Sub
  166.  
  167. Sub Data1_Reposition ()
  168.   Dim bm As String
  169.   Dim ds As dynaset
  170.  
  171.   If JustUsedFind = True Then
  172.     Set ds = Data1.Recordset.Clone()
  173.     bm = Data1.Recordset.Bookmark
  174.     ds.MoveFirst
  175.     CurrRec = 1
  176.     While ds.Bookmark <> bm
  177.       CurrRec = CurrRec + 1
  178.       ds.MoveNext
  179.     Wend
  180.     JustUsedFind = False
  181.   End If
  182.   SetRecNum
  183.  
  184. End Sub
  185.  
  186. Sub Data1_Validate (Action As Integer, Save As Integer)
  187.   On Error GoTo ValErr
  188.  
  189.   'first check for a move from an addnew or edit record
  190.   If Action < 5 Then
  191.     SetRecNum
  192.   End If
  193.  
  194.   Select Case Action
  195.     Case 1          'First
  196.       CurrRec = 1
  197.  
  198.     Case 2          'Previous
  199.       If CurrRec = 1 Then Beep
  200.       If CurrRec <> 1 Then CurrRec = CurrRec - 1
  201.  
  202.     Case 3          'Next
  203.       If CurrRec = TotRec Then Beep
  204.       If CurrRec <> TotRec Then CurrRec = CurrRec + 1
  205.  
  206.     Case 4          'Last
  207.       CurrRec = TotRec
  208.  
  209.     Case 5          'AddNew
  210.       'do nothing
  211.  
  212.     Case 6          'Update
  213.  
  214.     Case 7          'Delete
  215.       TotRec = TotRec - 1
  216.       SetRecNum
  217.  
  218.     Case 8
  219.       'set the flag for use in the reposition event
  220.       JustUsedFind = True
  221.  
  222.     Case 9          'BookMark
  223.       'do nothing"
  224.  
  225.     Case 10          'Close
  226.  
  227.   End Select
  228.  
  229.   GoTo ValEnd
  230.  
  231. ValErr:
  232.   Resume ValEnd
  233.  
  234. ValEnd:
  235.  
  236. End Sub
  237.  
  238. Sub Form_Load ()
  239. Dim ds2 As dynaset
  240. On Error GoTo LoadErr
  241.   Data1.Refresh
  242.  
  243.   CurrRec = 1
  244.   Set ds2 = Data1.Recordset.Clone()
  245.   If ds2.BOF = False Then
  246.     ds2.MoveLast
  247.     TotRec = ds2.RecordCount
  248.   Else
  249.     TotRec = 0
  250.   End If
  251.   ds2.Close
  252.  
  253.   SetRecNum
  254.   GoTo LoadEnd
  255.  
  256. LoadErr:
  257.   Unload Me
  258.   Resume LoadEnd
  259.  
  260. LoadEnd:
  261.  
  262.  
  263. End Sub
  264.  
  265. Sub SetRecNum ()
  266.  
  267. If Data1.EditMode <> 2 Then
  268.  
  269.     If Data1.Recordset.BOF = True Then
  270.       Data1.Caption = "Record BOF of " & TotRec
  271.     ElseIf Data1.Recordset.EOF = True Then
  272.       Data1.Caption = "Record EOF of " & TotRec
  273.     Else
  274.       Data1.Caption = "Record " & CurrRec & " of " & TotRec
  275.       Label1.Caption = "Record " & CurrRec & " of " & TotRec
  276.     End If
  277.   End If
  278. End Sub
  279.  
  280.